package thinker;

import gui.Gui;

import chess.ChessBoard;
import comm.*;

public class Thinker {

	public static final int MODE_PVC = 0;
	public static final int MODE_CVC = 1;

	private byte color;
	private Gui gui;
	private int mode;
	private ChessBoard currentBoard;
	private AIThinker searcher;

	public Thinker(byte clr, Gui g) {
		color = clr;
		gui = g;
		mode = g.isLocal() ? 0 : 1;
		searcher = new AIThinker(color);
	}

	public ChessInfo nextMove(ChessBoard b) {
		currentBoard = b;
		switch (mode) {
		case MODE_PVC:
			return moveByP();
		case MODE_CVC:
			return moveByC();
		}
		return moveByC();
	}

	public ChessInfo moveByP() {
		byte[] rs = { 0, 0, 0, 0 };
		while (!gui.isChessed())
			;
		gui.setChessed(false);
		return new ChessInfo((byte) 0, color, (byte) gui.getrow(), (byte) gui
				.getcol(), rs);
	}

	public ChessInfo moveByC() {
		return searcher.nextMove(currentBoard);
	}

}
